﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Paper 的摘要说明
/// </summary>
public class Paper
{
    public const string StrPaper = "paper";
    public const int NoneFlag = 0; //未提交
    public const int PastFlag = 1; //通过
    public const int AcceptFlag = 2;  //接受，修改即通过
    public const int SuspendFlag = 3;  //在审
    public const int FailFlag = 4;  //打回
    public const int ModifyFlag = 3;  //修改过后再审

    public int StudentGuid;
    public int ExpertGuid;
    public int PaperStatus;
    public int Count;
    public DateTime CreateTime;
    public string Title;
    public string FileName;
    public string Intro;
    public string Keywords;
    public int CategoryGuid;
	public Paper(int g)
	{
        this.StudentGuid = g;
        string sql = "select ExpertGuid as n from Student where UserGuid="+g.ToString();
        this.ExpertGuid = Convert.ToInt32(Fun.GetField(sql));
        sql = "select CategoryGuid as n from Student where UserGuid=" + g.ToString();
        this.CategoryGuid = Convert.ToInt32(Fun.GetField(sql));
        sql = "select * from Paper where StudentGuid="+g.ToString();
        DataTable dt = Fun.CreateDt(sql);
        this.Count = dt.Rows.Count;
        if (this.Count > 0)
        {
            DataRow dr = dt.Rows[this.Count - 1];
            this.PaperStatus = Convert.ToInt32(dr["Flag"]);
            this.Title = dr["Title"].ToString();
            this.FileName = dr["FileName"].ToString().Trim();
            this.CreateTime = Convert.ToDateTime(dr["CreateTime"]);
            this.Intro = dr["Intro"].ToString().Trim();
            this.Keywords = dr["Keywords"].ToString().Trim();
        }
        else
        {
            this.PaperStatus = 0;
            this.Title = "";
            this.FileName = "";
            this.CreateTime = DateTime.Now;
            this.Intro = "";
            this.Keywords = "";
        }
	}

    public static void Delete(int sg)
    {
        string sql = "select Guid from Paper where StudentGuid="+sg.ToString();
        DataTable dt = Fun.CreateDt(sql);
        foreach (DataRow dr in dt.Rows)
        {
            PaperFile.Delete(Convert.ToInt32(dr[0]));
        }
    }

    public static int Distribute(int g)
    {
        Student stu = new Student(g);
        Doctor doc = new Doctor(stu.DoctorGuid);
        string sql = "select top 1 UserGuid as n from Doctor where Expert=1 and TeamGuid!="+doc.TeamGuid.ToString()+" order by newid()";
        int eg = Convert.ToInt32(Fun.GetField(sql));
        stu.ExpertGuid = eg;
        stu.Update();
        return eg;
    }

    public static string Tip(int f)
    {
        switch (f)
        {
            case 0:
                return "未提交";
                break;
            case 1:
                return "通过";
                break;
            case 2:
                return "通过";
                break;
            case 3:
                return "在审";
                break;
            case 4:
                return "打回";
                break;
            case 5:
                return "修改再审";
                break;
            default:
                return "";
                break;
        }
    }

    public string Status
    {
        get
        {
            return Tip(this.PaperStatus);
        }
    }
}
